package com.eonmind.ai.service.impl;

import com.eonmind.ai.mapper.AiPlatformMapper;
import com.eonmind.ai.mapper.AiPlatformModelMapper;
import com.eonmind.ai.service.IAiPlatformService;
import com.eonmind.common.contract.enums.DelEnum;
import com.eonmind.common.contract.enums.StatusEnum;
import com.eonmind.common.provider.entity.ai.AiPlatform;
import com.eonmind.common.provider.entity.ai.AiPlatformModel;
import com.mongoplus.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Slf4j
@Service
public class AiPlatformService implements IAiPlatformService {
    @Resource
    private AiPlatformMapper aiPlatformMapper;

    @Resource
    private AiPlatformModelMapper aiPlatformModelMapper;

    @Override
    public List<AiPlatform> getPlatformsByStatus(Integer status) {
        if (ObjectUtils.isEmpty(status)) {
            return new ArrayList<>();
        }
        QueryWrapper<AiPlatform> eq = aiPlatformMapper.createMgoQuery()
                .eq(AiPlatform.Fields.status, status);
        return aiPlatformMapper.list(eq);
    }

    @Override
    public List<AiPlatformModel> getPlatformModelByStatus(Integer status) {
        if (ObjectUtils.isEmpty(status)) {
            return new ArrayList<>();
        }
        QueryWrapper<AiPlatformModel> eq = aiPlatformModelMapper.createMgoQuery()
                .eq(AiPlatformModel.Fields.status, status);

        return aiPlatformModelMapper.list(eq);
    }

    @Override
    public List<AiPlatform> getByIds(Collection<Long> platformIds) {
        QueryWrapper<AiPlatform> in = aiPlatformMapper.createMgoQuery()
                .in(AiPlatform::getId, platformIds);
        return aiPlatformMapper.list(in);
    }

    @Override
    public AiPlatform getPlatformById(Long platformId) {
        QueryWrapper<AiPlatform> in = aiPlatformMapper.createMgoQuery()
                .eq(AiPlatform::getId, platformId)
                .eq(AiPlatform::getDel, DelEnum.UN_DEL.getCode())
                .eq(AiPlatform::getStatus, StatusEnum.OPENED.getCode());
        return aiPlatformMapper.one(in);
    }


}
